package com.ws.demo1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ws.demo1.demos.ChanAnalyzer;
import com.ws.demo1.demos.domain.Fractal;
import com.ws.demo1.demos.domain.MarketData;
import com.ws.demo1.demos.domain.Pen;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.client.RestTemplate;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

//@SpringBootApplication
public class Demo1Application {

    // 1日线，2 其他
    public static int lineType = 2;
    public static DateTimeFormatter dateF = DateTimeFormatter.ofPattern("yyyyMMdd");
    public static DateTimeFormatter timeF = DateTimeFormatter.ofPattern("HHmm");

    public static void main(String[] args) {
        List<MarketData> marketData = ChanAnalyzer.fetchOriginalData();
        List<Fractal> fractals = ChanAnalyzer.detectFractals(marketData);
        List<Pen> pens = ChanAnalyzer.buildPens(fractals,/*minDeltaAbs*/ 0.5, /*minDeltaPct*/ 0.001);

        for (Pen pen : pens) {
            String color = "COLORFFFFD000";
            if (lineType == 2) {

                String sDate;
                String sTime = pen.start.getTime().format(timeF);
                // 如果时间大于晚上9点，日期加一天
                if (Integer.parseInt(sTime) >= 2100) {
                    sDate = pen.start.getTime().plusDays(1).format(dateF);
                } else {
                    sDate = pen.start.getTime().format(dateF);
                }

                String eDate;
                String eTime = pen.end.getTime().format(timeF);
                if (Integer.parseInt(eTime) >= 2100) {
                    eDate = pen.end.getTime().plusDays(1).format(dateF);
                } else {
                    eDate = pen.end.getTime().format(dateF);
                }

                System.out.printf("DRAWLINE1( DATE = %s && TIME = %s, %.2f, DATE = %s && TIME = %s, %.2f, 0), %s, LINETHICK2;%n",
                        sDate,
                        sTime,
                        pen.start.price,
                        eDate,
                        eTime,
                        pen.end.price,
                        color
                );
            }
        }
    }



}
